package com.acwing.partition20;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/4/29 8:08
 */
public class AC1995见面与问候 {

    private static final int N = 1000010;
    //a[i]、b[i]分别表示在i时刻a、b的位置
    private static int[] a = new int[N], b = new int[N];
    private static int n, m;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = nextInt(); m = nextInt();
        int lasta = 1, lastb = 1;
        for (int i = 0; i < n; i++) {
            int s = nextInt();
            char d = next().charAt(0);
            for (int j = 0; j < s; j++, lasta++) {
                if (d == 'R') a[lasta] = a[lasta - 1] + 1;
                else a[lasta] = a[lasta - 1] - 1;
            }
        }
        for (int i = 0; i < m; i++) {
            int s = nextInt();
            char d = next().charAt(0);
            for (int j = 0; j < s; j++, lastb++) {
                if (d == 'R') b[lastb] = b[lastb - 1] + 1;
                else b[lastb] = b[lastb - 1] - 1;
            }
        }
        int ans = 0;
        //根据时间找位置，需要判断相遇的情况
        for (int i = 1; i < lasta || i < lastb; i++) {
            if (i >= lasta) a[i] = a[i - 1];
            if (i >= lastb) b[i] = b[i - 1];
            if (Math.abs(a[i] - a[i - 1] + b[i] - b[i - 1]) < 2 && a[i] == b[i]) ans++;
        }
        writer.println(ans);
        writer.flush();
    }

    private static String next() throws IOException {
        tokenizer.nextToken();
        return tokenizer.sval;
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
